<?php
echo '<div id="nameplate">Az oldalon megtalálható filmek</div>';
require_once 'dbconnect.php';
if (!isset($_GET['pagenum'])) {
    $pagenum = 1;
} else {
    $pagenum = $_GET['pagenum'];
}
if (!isset($_GET['filter'])) {
    $filter = "";
} elseif ($_GET['filter'] == 'num') {
    $filter = '[0-9]';
} elseif ($_GET['filter'] == 'symb') {
    $filter = '(\\\\*|\\\\-|\\\\+|\\\\.|\\\\,|\\\\?|\\\\;|\\\\!)';
} else {
    $filter = $_GET['filter'];
}
$data = mysql_query("SELECT * FROM movies WHERE hun_title REGEXP '^$filter'") or die(mysql_error());
$rows = mysql_num_rows($data);
if ($rows == 0) {
    include 'navigator.php';
    echo 'Nincs ilyen';
} else {
    $page_rows = 10;
    $last = ceil($rows / $page_rows);
    if ($pagenum < 1) {
        $pagenum = 1;
    } elseif ($pagenum > $last) {
        $pagenum = $last;
    }
    $start = ($pagenum - 1) * $page_rows;
    $previous = $pagenum - 1;
    $next = $pagenum + 1;
    $query = mysql_query("SELECT * FROM movies WHERE hun_title REGEXP '^$filter' LIMIT $start, $page_rows") or die(mysql_error());
    include 'navigator.php';
    ?>
    <div id="tabla">
        <table border="1" width="400" align="center" class="sortable">
            <thead id="header">
                <tr>
                    <th class="sorttable_nosort">Kép</th>
                    <th>
                        <span id="title_header">Cím</span>
                    </th>
                    <th>
                        <span id="year_header">Év</span>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php
                while ($lista = mysql_fetch_array($query)) {
                    ?>
                    <tr>
                        <td>
                            <a href="index.php?show=film&id=<?php echo $lista['id']; ?>">
                                <img src="kepek/<?php echo $lista['poster']; ?>" id="thumb"/>
                            </a>
                        </td>
                        <td>
                            <a href="index.php?show=film&id=<?php echo $lista['id']; ?>">
                                <?php echo $lista['hun_title']; ?>
                            </a>
                        </td>
                        <td>
                            <p><?php echo $lista['year']; ?></p>
                        </td>
                    </tr>
                    <?php
                }
                ?>
            </tbody>
        </table>
    </div>
    <?php
    include 'lapozo.php';
}
?>